﻿Imports System.Data.SqlClient
Module action
    Dim DA As SqlDataAdapter
    Dim CB As SqlCommandBuilder
    Public TBL As DataTable
    Public rowIndex As Integer = 0
    Public Function GetConnection() As SqlConnection
        Dim cn As New SqlConnection("Server=.\SQLEXPRESS; uid=sa; pwd=123; database=HOTEL;")
        cn.Open()
        Return cn
    End Function
    Public Sub ExecuteNonquery(ByVal sql As String)
        Dim cmd As New SqlCommand(sql, GetConnection)
        cmd.ExecuteNonQuery()
    End Sub
    Public Function ExcecuteScalar(ByVal sql As String) As Object
        Dim cmd As New SqlCommand(sql, GetConnection)
        Dim val = cmd.ExecuteScalar
        Return val
    End Function
    Public Function ExcecuteDatatable(ByVal sql As String) As DataTable
        Dim cmd As New SqlCommand(sql, GetConnection)
        Dim dr As SqlDataReader = cmd.ExecuteReader
        Dim dt As New DataTable
        dt.Load(dr)
        dr.Close()
        Return dt
    End Function
    Public Sub loadtable(ByVal sql As String)
        'Dim rowIndex As Integer = 0
        DA = New SqlDataAdapter(sql, GetConnection)
        CB = New SqlCommandBuilder(DA)
        TBL = New DataTable
        DA.Fill(TBL)
    End Sub
    
End Module
